package org.grey.edz.util;

import java.util.function.Predicate;
import java.util.function.Supplier;

/**
 * @program: easy-data-zipper
 * @ClassName EDZAssert
 * @description:
 * @author: Grey
 * @create: 2024-02-19 16:35
 */
public class EDZAssert {

    public static <T> T getOrElse(Boolean flag, Supplier<T> getWhenTrue,Supplier<T> getElse){
        if(flag)
            return getWhenTrue.get();
        return getElse.get();
    }

    public static <T> T getWhenTrue(Boolean flag, Supplier<T> supplier){
        if(flag)
            return supplier.get();
        return null;
    }

    public static void throwWhenTrue(Predicate<?> predicate, RuntimeException re){
        if(predicate.test(null))
            throw re;
    }

    public static void throwWhenTrue(Boolean flag, RuntimeException re){
        if(flag)
            throw re;
    }

}
